 import {
  Body,
  Controller,
  Delete,
  Get,
  Param,
  Post,
  Patch,
} from '@nestjs/common';
import { Permission } from '../public/permission.decorator';
import { Company } from '@app/models/company';
import { CompanyService } from './company.service';

@Controller('company')
export class CompanyController {
  constructor(private readonly companyService: CompanyService) {}

  @Get()
  @Permission('company::info')
  getCompanies() {
    return this.companyService.getCompanies();
  }

  @Get('info/:id')
  @Permission('company::info')
  findOne(@Param('id') id: number) {
    return this.companyService.getCompany(id);
  }

  @Post()
  @Permission('company::add')
  async add(@Body() body: Company) {
    return this.companyService.add(body);
  }

  @Patch()
  @Permission('company::update')
  async update(@Body() body: Company) {
    return this.companyService.update(body);
  }

  @Delete('/:id')
  @Permission('company::del')
  async del(@Param('id') id: number) {
    return this.companyService.del(id);
  }  
}